/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-06 17:36:29
 * @LastEditors: 赵大壮
 */
import uploadFile from "@/utils/DZUploadFile";
import { Component, Vue, Inject } from "vue-property-decorator";
import DZServiceGoods from "../../service/DZServiceGoods";
import UITinymceEditor from "@/components/ui-editor/UITinymceEditor.vue"
@Component({
    components: { UITinymceEditor }
})
export default class Index extends Vue {

    s_goods = new DZServiceGoods();

    bool_edit = false;

    created() {
    }

    mounted() {
        var goodsId = this.$route.query.id ? this.$route.query.id as string : ''
        if (goodsId) {
            this.s_goods.m_goods.id = goodsId;
            this.bool_edit = true;
            this.s_goods.net_info_goods(goodsId);
        }
        this.s_goods.net_list_assess_dic();
        this.s_goods.net_list_export_dic();
    }

    beforeDestroy() {

    }

    action_select_list_cover(file) {
        if (file.status == "ready") {
            this.s_goods.m_goods.listCoverUrl = URL.createObjectURL(file.raw);
            uploadFile.uploadImage(file.raw,
                (res) => {
                }, (res) => {
                    this.s_goods.m_goods.listCover = res;
                }, (res) => {
                    this.s_goods.m_goods.listCover = "";
                });
        }
    }

    action_select_banner_cover(file) {
        if (file.status == "ready") {
            this.s_goods.m_goods.infoCoverUrl = URL.createObjectURL(file.raw);
            uploadFile.uploadImage(file.raw,
                (res) => {
                }, (res) => {
                    this.s_goods.m_goods.infoCover = res;
                }, (res) => {
                    this.s_goods.m_goods.infoCover = "";
                });
        }
    }

    action_select_report_cover(file) {
        if (file.status == "ready") {
            this.s_goods.m_goods.reportCoverUrl = URL.createObjectURL(file.raw);
            uploadFile.uploadImage(file.raw,
                (res) => {
                }, (res) => {
                    this.s_goods.m_goods.reportCover = res;
                }, (res) => {
                    this.s_goods.m_goods.reportCover = "";
                });
        }
    }

    action_change_type(val) {
        this.s_goods.m_goods.typeId = '';
        if (val == 1) {
            this.s_goods.list_type_data = this.s_goods.list_assess_dic;
        } else {
            this.s_goods.list_type_data = this.s_goods.list_export_dic;
        }
    }

    action_editor_change(text) {
        this.s_goods.m_goods.content = text;
    }

    action_change_activity(val) {

    }

    action_add_goods() {
        if (this.bool_edit) {
            this.s_goods.net_edit_goods(() => {
                this.$router.back();
            });
        } else {
            this.s_goods.net_add_goods(() => {
                this.$router.back();
            });
        }
    }
}